<template>
  <el-container>
    <el-header>
      <div>
        <div class="logo">
          <img src="@/assets/logo.png" alt="" />
        </div>
        <span>药易购商家管理系统</span>
      </div>
      <el-button type="info" @click="logout">退出</el-button>
    </el-header>
    <el-container v-if="toexamine">
      <el-aside :width="isCollapse ? '64px' : '200px'">
        <!-- 折叠效果 -->
        <div class="toggle-button" @click="isCollapse = !isCollapse">|||</div>
        <!-- 侧边栏菜单区 -->
        <el-menu
          background-color="#333744"
          text-color="#fff"
          active-text-color="#409EFF"
          :unique-opened="true"
          :collapse="isCollapse"
          :collapse-transition="false"
          :router="true"
          :default-active="activePath"
        >
          <el-submenu
            :index="item.id + ''"
            v-for="item in menulist"
            :key="item.id"
          >
            <template slot="title">
              <i :class="iconsObj[item.id]"></i>
              <span>{{ item.authName }}</span>
            </template>
            <el-menu-item
              :index="'/' + subItem.path"
              v-for="subItem in item.children"
              :key="subItem.id"
              @click="saveNavState('/' + subItem.path)"
              ><template slot="title">
                <i class="el-icon-menu"></i>
                <span>{{ subItem.authName }}</span>
              </template></el-menu-item
            >
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>
        <!-- 路由占位符-->
        <router-view></router-view>
      </el-main>
    </el-container>
    <!-- 审核 -->
    <Examine />
  </el-container>
</template>
<script>
import Examine from "@/components/Examine/index.vue";
import { menulist } from "@/api/login/index.js";
export default {
  name: "Home",
  components: { Examine },
  data() {
    return {
      //是否已经审核
      toexamine: true,
      //左侧菜单数据
      menulist: [],
      //左侧菜单图标
      iconsObj: {
        125: "iconfont icon-user",
        103: "iconfont icon-tijikongjian",
        101: "iconfont icon-shangpin",
        102: "iconfont icon-danju",
        145: "iconfont icon-baobiao",
      },
      //折叠
      isCollapse: false,
      //被激活的链接地址
      activePath: "",
    };
  },
  created() {
    this.toexamine = false;
    if (this.toexamine) {
      this.getmenulist();
      this.activePath = window.sessionStorage.getItem("activePath");
    }
  },
  methods: {
    /**
     * @desc :退出登录
     * @params :
     * @author : liangdecheng
     **/
    logout() {
      window.sessionStorage.clear();
      this.$router.push("/");
    },
    /**
     * @desc :获取菜单栏数据
     * @date :
     * @params :
     * @author : liangdecheng
     **/
    async getmenulist() {
      await menulist().then((response) => {
        let res = response.data;
        if (res.meta.status != 200) return this.$message.error(res.meta.msg);
        this.menulist = res.data;
      });
    },
    /**
     * @desc :保持链接的激活状态
     * @date :
     * @params :
     * @author : liangdecheng
     **/
    saveNavState(activePath) {
      window.sessionStorage.setItem("activePath", activePath);
      this.activePath = activePath;
    },
  },
};
</script>
<style lang="less" scoped>
.el-container {
  height: 100%;
}
.el-header {
  background-color: #373d41;
  display: flex;
  justify-content: space-between;
  padding-left: 0;
  align-items: center;
  color: #fff;
  font-size: 20px;
  > div {
    display: flex;
    align-items: center;
    span {
      margin-left: 15px;
    }
  }
}
.el-aside {
  background-color: #333744;
  .el-menu {
    border-right: none;
  }
}
.el-main {
  background-color: #eaedf1;
}
.logo {
  display: inline-block;
  height: 60px;
  width: 60px;
  img {
    width: 100%;
    height: 100%;
  }
}
.iconfont {
  margin-right: 5px;
}
.toggle-button {
  background-color: #4a5064;
  font-size: 10px;
  line-height: 24px;
  color: #fff;
  text-align: center;
  letter-spacing: 0.3em;
  cursor: pointer;
  //设置字体不能被选中
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}
</style>